﻿#include <appbase.h>
#include <mainwindows.h>
#include <QApplication>

#include <locale>
#include <QLocale>
#include <QTextCodec>
#include <QLockFile>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    /*
     * 当前运行程序路径
     * */
    const QString thisAppPath = a.applicationDirPath();

    /*
     * 文件锁路径
     * */
    const QString thisFileLock = thisAppPath + "/ChMS.lock";

    // 配置编码
    QTextCodec* isCodec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(isCodec);

    QByteArray encodedString = "小鸡炖蘑菇";
    QTextCodec * varGB18030Codec = QTextCodec::codecForName("GB18030");
    QString varQSTitleTmp = varGB18030Codec->toUnicode(encodedString);

    // 检查文件锁，确认程序是否发生多开。
    QLockFile lockApp(thisFileLock);
    if(!lockApp.tryLock()){
        return 0;
    }

    a.setWindowIcon(QIcon(":/res/img/ChMS-1.png"));

    MainWindows mainwin;
    mainwin.setWindowTitle(varQSTitleTmp);
    mainwin.show();

    return a.exec();
}
